home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / calc / calc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-01  |  20.7 KB  |  597 lines

  1. VERSION 2.00
  2. Begin Form Calculator 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Calculator"
  6.    ClientHeight    =   4140
  7.    ClientLeft      =   2745
  8.    ClientTop       =   2085
  9.    ClientWidth     =   3705
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    FontBold        =   -1  'True
  13.    FontItalic      =   0   'False
  14.    FontName        =   "System"
  15.    FontSize        =   9.75
  16.    FontStrikethru  =   0   'False
  17.    FontUnderline   =   0   'False
  18.    Height          =   4545
  19.    Icon            =   CALC.FRX:0000
  20.    Left            =   2685
  21.    LinkMode        =   1  'Source
  22.    LinkTopic       =   "Form1"
  23.    MaxButton       =   0   'False
  24.    ScaleHeight     =   4140
  25.    ScaleWidth      =   3705
  26.    Top             =   1740
  27.    Width           =   3825
  28.    Begin SSPanel Panel3D2 
  29.       BackColor       =   &H00C0C0C0&
  30.       BevelInner      =   1  'Inset
  31.       BevelWidth      =   2
  32.       BorderWidth     =   6
  33.       Font3D          =   0  'None
  34.       ForeColor       =   &H00000000&
  35.       Height          =   3915
  36.       Left            =   75
  37.       TabIndex        =   1
  38.       Top             =   105
  39.       Width           =   3555
  40.       Begin SSPanel Panel3D5 
  41.          BackColor       =   &H00C0C0C0&
  42.          BevelInner      =   1  'Inset
  43.          BorderWidth     =   1
  44.          Font3D          =   0  'None
  45.          ForeColor       =   &H00000000&
  46.          Height          =   375
  47.          Left            =   210
  48.          ShadowColor     =   1  'Black
  49.          TabIndex        =   24
  50.          Top             =   195
  51.          Width           =   1035
  52.          Begin SSPanel Panel3D7 
  53.             BackColor       =   &H0000FF00&
  54.             BevelInner      =   2  'Raised
  55.             BevelOuter      =   0  'None
  56.             BevelWidth      =   2
  57.             BorderWidth     =   1
  58.             Caption         =   "ON"
  59.             Font3D          =   1  'Raised w/light shading
  60.             FontBold        =   -1  'True
  61.             FontItalic      =   0   'False
  62.             FontName        =   "Arial"
  63.             FontSize        =   8.25
  64.             FontStrikethru  =   0   'False
  65.             FontUnderline   =   0   'False
  66.             ForeColor       =   &H00000000&
  67.             Height          =   285
  68.             Left            =   60
  69.             ShadowColor     =   1  'Black
  70.             TabIndex        =   25
  71.             Top             =   60
  72.             Width           =   450
  73.          End
  74.          Begin SSPanel Panel3D6 
  75.             BevelOuter      =   0  'None
  76.             BorderWidth     =   1
  77.             Caption         =   "OFF"
  78.             Font3D          =   3  'Inset w/light shading
  79.             FontBold        =   -1  'True
  80.             FontItalic      =   0   'False
  81.             FontName        =   "Arial"
  82.             FontSize        =   8.25
  83.             FontStrikethru  =   0   'False
  84.             FontUnderline   =   0   'False
  85.             ForeColor       =   &H000000FF&
  86.             Height          =   210
  87.             Left            =   570
  88.             ShadowColor     =   1  'Black
  89.             TabIndex        =   26
  90.             Top             =   90
  91.             Width           =   375
  92.          End
  93.       End
  94.       Begin SSPanel Panel3D4 
  95.          BevelInner      =   1  'Inset
  96.          BorderWidth     =   1
  97.          Caption         =   "CZAPPATRONICS"
  98.          Font3D          =   2  'Raised w/heavy shading
  99.          ForeColor       =   &H00FF0000&
  100.          Height          =   390
  101.          Left            =   1290
  102.          ShadowColor     =   1  'Black
  103.          TabIndex        =   23
  104.          Top             =   180
  105.          Width           =   2070
  106.       End
  107.       Begin SSPanel Panel3D3 
  108.          BackColor       =   &H00000000&
  109.          BevelOuter      =   1  'Inset
  110.          BevelWidth      =   2
  111.          BorderWidth     =   2
  112.          Font3D          =   2  'Raised w/heavy shading
  113.          ForeColor       =   &H00FF0000&
  114.          Height          =   525
  115.          Left            =   210
  116.          TabIndex        =   22
  117.          Top             =   615
  118.          Width           =   3150
  119.          Begin Label ReadOut 
  120.             Alignment       =   1  'Right Justify
  121.             BackColor       =   &H0000FFFF&
  122.             BorderStyle     =   1  'Fixed Single
  123.             Caption         =   "0."
  124.             FontBold        =   -1  'True
  125.             FontItalic      =   0   'False
  126.             FontName        =   "MS Sans Serif"
  127.             FontSize        =   13.5
  128.             FontStrikethru  =   0   'False
  129.             FontUnderline   =   0   'False
  130.             Height          =   420
  131.             Left            =   45
  132.             TabIndex        =   2
  133.             Top             =   60
  134.             Width           =   3075
  135.          End
  136.       End
  137.       Begin SSPanel Panel3D1 
  138.          BackColor       =   &H00808080&
  139.          BevelInner      =   2  'Raised
  140.          BorderWidth     =   1
  141.          Font3D          =   2  'Raised w/heavy shading
  142.          ForeColor       =   &H00FF0000&
  143.          Height          =   2520
  144.          Left            =   210
  145.          TabIndex        =   3
  146.          Top             =   1170
  147.          Width           =   3165
  148.          Begin CommandButton Number 
  149.             BackColor       =   &H00C0C0C0&
  150.             Caption         =   "7"
  151.             FontBold        =   -1  'True
  152.             FontItalic      =   0   'False
  153.             FontName        =   "System"
  154.             FontSize        =   9.75
  155.             FontStrikethru  =   0   'False
  156.             FontUnderline   =   0   'False
  157.             Height          =   480
  158.             Index           =   7
  159.             Left            =   90
  160.             TabIndex        =   0
  161.             Top             =   135
  162.             Width           =   480
  163.          End
  164.          Begin CommandButton Number 
  165.             BackColor       =   &H00C0C0C0&
  166.             Caption         =   "8"
  167.             FontBold        =   -1  'True
  168.             FontItalic      =   0   'False
  169.             FontName        =   "System"
  170.             FontSize        =   9.75
  171.             FontStrikethru  =   0   'False
  172.             FontUnderline   =   0   'False
  173.             Height          =   480
  174.             Index           =   8
  175.             Left            =   690
  176.             TabIndex        =   21
  177.             Top             =   135
  178.             Width           =   480
  179.          End
  180.          Begin CommandButton Number 
  181.             BackColor       =   &H00C0C0C0&
  182.             Caption         =   "9"
  183.             FontBold        =   -1  'True
  184.             FontItalic      =   0   'False
  185.             FontName        =   "System"
  186.             FontSize        =   9.75
  187.             FontStrikethru  =   0   'False
  188.             FontUnderline   =   0   'False
  189.             Height          =   480
  190.             Index           =   9
  191.             Left            =   1290
  192.             TabIndex        =   20
  193.             Top             =   135
  194.             Width           =   480
  195.          End
  196.          Begin CommandButton Cancel 
  197.             BackColor       =   &H00C0C0C0&
  198.             Caption         =   "C"
  199.             FontBold        =   -1  'True
  200.             FontItalic      =   0   'False
  201.             FontName        =   "System"
  202.             FontSize        =   9.75
  203.             FontStrikethru  =   0   'False
  204.             FontUnderline   =   0   'False
  205.             Height          =   480
  206.             Left            =   2010
  207.             TabIndex        =   19
  208.             Top             =   135
  209.             Width           =   480
  210.          End
  211.          Begin CommandButton CancelEntry 
  212.             BackColor       =   &H0000FFFF&
  213.             Caption         =   "CE"
  214.             FontBold        =   -1  'True
  215.             FontItalic      =   0   'False
  216.             FontName        =   "System"
  217.             FontSize        =   9.75
  218.             FontStrikethru  =   0   'False
  219.             FontUnderline   =   0   'False
  220.             Height          =   480
  221.             Left            =   2610
  222.             TabIndex        =   18
  223.             Top             =   135
  224.             Width           =   480
  225.          End
  226.          Begin CommandButton Number 
  227.             BackColor       =   &H00C0C0C0&
  228.             Caption         =   "4"
  229.             FontBold        =   -1  'True
  230.             FontItalic      =   0   'False
  231.             FontName        =   "System"
  232.             FontSize        =   9.75
  233.             FontStrikethru  =   0   'False
  234.             FontUnderline   =   0   'False
  235.             Height          =   480
  236.             Index           =   4
  237.             Left            =   90
  238.             TabIndex        =   17
  239.             Top             =   735
  240.             Width           =   480
  241.          End
  242.          Begin CommandButton Number 
  243.             BackColor       =   &H00C0C0C0&
  244.             Caption         =   "5"
  245.             FontBold        =   -1  'True
  246.             FontItalic      =   0   'False
  247.             FontName        =   "System"
  248.             FontSize        =   9.75
  249.             FontStrikethru  =   0   'False
  250.             FontUnderline   =   0   'False
  251.             Height          =   480
  252.             Index           =   5
  253.             Left            =   690
  254.             TabIndex        =   16
  255.             Top             =   735
  256.             Width           =   480
  257.          End
  258.          Begin CommandButton Number 
  259.             BackColor       =   &H00C0C0C0&
  260.             Caption         =   "6"
  261.             FontBold        =   -1  'True
  262.             FontItalic      =   0   'False
  263.             FontName        =   "System"
  264.             FontSize        =   9.75
  265.             FontStrikethru  =   0   'False
  266.             FontUnderline   =   0   'False
  267.             Height          =   480
  268.             Index           =   6
  269.             Left            =   1290
  270.             TabIndex        =   15
  271.             Top             =   735
  272.             Width           =   480
  273.          End
  274.          Begin CommandButton Operator 
  275.             BackColor       =   &H00C0C0C0&
  276.             Caption         =   "+"
  277.             FontBold        =   -1  'True
  278.             FontItalic      =   0   'False
  279.             FontName        =   "System"
  280.             FontSize        =   9.75
  281.             FontStrikethru  =   0   'False
  282.             FontUnderline   =   0   'False
  283.             Height          =   480
  284.             Index           =   1
  285.             Left            =   2010
  286.             TabIndex        =   14
  287.             Top             =   735
  288.             Width           =   480
  289.          End
  290.          Begin CommandButton Operator 
  291.             BackColor       =   &H00C0C0C0&
  292.             Caption         =   "-"
  293.             FontBold        =   -1  'True
  294.             FontItalic      =   0   'False
  295.             FontName        =   "System"
  296.             FontSize        =   9.75
  297.             FontStrikethru  =   0   'False
  298.             FontUnderline   =   0   'False
  299.             Height          =   480
  300.             Index           =   3
  301.             Left            =   2610
  302.             TabIndex        =   13
  303.             Top             =   735
  304.             Width           =   480
  305.          End
  306.          Begin CommandButton Number 
  307.             BackColor       =   &H00C0C0C0&
  308.             Caption         =   "1"
  309.             FontBold        =   -1  'True
  310.             FontItalic      =   0   'False
  311.             FontName        =   "System"
  312.             FontSize        =   9.75
  313.             FontStrikethru  =   0   'False
  314.             FontUnderline   =   0   'False
  315.             Height          =   480
  316.             Index           =   1
  317.             Left            =   90
  318.             TabIndex        =   12
  319.             Top             =   1335
  320.             Width           =   480
  321.          End
  322.          Begin CommandButton Number 
  323.             BackColor       =   &H00C0C0C0&
  324.             Caption         =   "2"
  325.             FontBold        =   -1  'True
  326.             FontItalic      =   0   'False
  327.             FontName        =   "System"
  328.             FontSize        =   9.75
  329.             FontStrikethru  =   0   'False
  330.             FontUnderline   =   0   'False
  331.             Height          =   480
  332.             Index           =   2
  333.             Left            =   690
  334.             TabIndex        =   11
  335.             Top             =   1335
  336.             Width           =   480
  337.          End
  338.          Begin CommandButton Number 
  339.             BackColor       =   &H00C0C0C0&
  340.             Caption         =   "3"
  341.             FontBold        =   -1  'True
  342.             FontItalic      =   0   'False
  343.             FontName        =   "System"
  344.             FontSize        =   9.75
  345.             FontStrikethru  =   0   'False
  346.             FontUnderline   =   0   'False
  347.             Height          =   480
  348.             Index           =   3
  349.             Left            =   1290
  350.             TabIndex        =   10
  351.             Top             =   1335
  352.             Width           =   480
  353.          End
  354.          Begin CommandButton Operator 
  355.             BackColor       =   &H00C0C0C0&
  356.             Caption         =   "X"
  357.             FontBold        =   -1  'True
  358.             FontItalic      =   0   'False
  359.             FontName        =   "System"
  360.             FontSize        =   9.75
  361.             FontStrikethru  =   0   'False
  362.             FontUnderline   =   0   'False
  363.             Height          =   480
  364.             Index           =   2
  365.             Left            =   2010
  366.             TabIndex        =   9
  367.             Top             =   1335
  368.             Width           =   480
  369.          End
  370.          Begin CommandButton Operator 
  371.             BackColor       =   &H00C0C0C0&
  372.             Caption         =   "/"
  373.             FontBold        =   -1  'True
  374.             FontItalic      =   0   'False
  375.             FontName        =   "System"
  376.             FontSize        =   9.75
  377.             FontStrikethru  =   0   'False
  378.             FontUnderline   =   0   'False
  379.             Height          =   480
  380.             Index           =   0
  381.             Left            =   2610
  382.             TabIndex        =   8
  383.             Top             =   1335
  384.             Width           =   480
  385.          End
  386.          Begin CommandButton Number 
  387.             BackColor       =   &H00C0C0C0&
  388.             Caption         =   "0"
  389.             FontBold        =   -1  'True
  390.             FontItalic      =   0   'False
  391.             FontName        =   "System"
  392.             FontSize        =   9.75
  393.             FontStrikethru  =   0   'False
  394.             FontUnderline   =   0   'False
  395.             Height          =   480
  396.             Index           =   0
  397.             Left            =   90
  398.             TabIndex        =   7
  399.             Top             =   1935
  400.             Width           =   1080
  401.          End
  402.          Begin CommandButton Decimal 
  403.             BackColor       =   &H00C0C0C0&
  404.             Caption         =   "."
  405.             FontBold        =   -1  'True
  406.             FontItalic      =   0   'False
  407.             FontName        =   "System"
  408.             FontSize        =   9.75
  409.             FontStrikethru  =   0   'False
  410.             FontUnderline   =   0   'False
  411.             Height          =   480
  412.             Left            =   1290
  413.             TabIndex        =   6
  414.             Top             =   1935
  415.             Width           =   480
  416.          End
  417.          Begin CommandButton Operator 
  418.             BackColor       =   &H00C0C0C0&
  419.             Caption         =   "="
  420.             FontBold        =   -1  'True
  421.             FontItalic      =   0   'False
  422.             FontName        =   "System"
  423.             FontSize        =   9.75
  424.             FontStrikethru  =   0   'False
  425.             FontUnderline   =   0   'False
  426.             Height          =   480
  427.             Index           =   4
  428.             Left            =   2010
  429.             TabIndex        =   5
  430.             Top             =   1935
  431.             Width           =   480
  432.          End
  433.          Begin CommandButton Percent 
  434.             BackColor       =   &H00C0C0C0&
  435.             Caption         =   "%"
  436.             FontBold        =   -1  'True
  437.             FontItalic      =   0   'False
  438.             FontName        =   "System"
  439.             FontSize        =   9.75
  440.             FontStrikethru  =   0   'False
  441.             FontUnderline   =   0   'False
  442.             Height          =   480
  443.             Left            =   2610
  444.             TabIndex        =   4
  445.             Top             =   1935
  446.             Width           =   480
  447.          End
  448.       End
  449.    End
  450. ' ------------------------------------------------------------------------
  451. '               Copyright (C) 1991 Microsoft Corporation
  452. ' You have a royalty-free right to use, modify, reproduce and distribute
  453. ' the Sample Application Files (and/or any modified version) in any way
  454. ' you find useful, provided that you agree that Microsoft has no warranty,
  455. ' obligations or liability for any Sample Application Files.
  456. ' ------------------------------------------------------------------------
  457. Option Explicit
  458. Dim Op1, Op2                ' Previously input operand.
  459. Dim DecimalFlag As Integer  ' Decimal point present yet?
  460. Dim NumOps As Integer       ' Number of operands.
  461. Dim LastInput               ' Indicate type of last keypress.
  462. Dim OpFlag                  ' Indicate pending operation.
  463. Dim TempReadout
  464. Dim MouseDownFlag As Integer
  465. Dim Counter As Integer
  466. ' Click event procedure for C (cancel) key.
  467. ' Reset the display and initializes variables.
  468. Sub Cancel_Click ()
  469.     ReadOut = "0."
  470.     Op1 = 0
  471.     Op2 = 0
  472.     Form_Load
  473. End Sub
  474. ' Click event procedure for CE (cancel entry) key.
  475. Sub CancelEntry_Click ()
  476.     ReadOut = "0."
  477.     DecimalFlag = False
  478.     LastInput = "CE"
  479. End Sub
  480. ' Click event procedure for decimal point (.) key.
  481. ' If last keypress was an operator, initialize
  482. ' readout to "0." Otherwise, append a decimal
  483. ' point to the display.
  484. Sub Decimal_Click ()
  485.     If LastInput = "NEG" Then
  486.     ReadOut = "-0."
  487.     ElseIf LastInput <> "NUMS" Then
  488.     ReadOut = "0."
  489.     End If
  490.     DecimalFlag = True
  491.     LastInput = "NUMS"
  492. End Sub
  493. ' Initialization routine for the form.
  494. ' Set all variables to initial values.
  495. Sub Form_Load ()
  496.     DecimalFlag = False
  497.     NumOps = 0
  498.     LastInput = "NONE"
  499.     OpFlag = " "
  500. End Sub
  501. ' Click event procedure for number keys (0-9).
  502. ' Appends new number to the number in the display.
  503. Sub Number_Click (Index As Integer)
  504.     If LastInput <> "NUMS" Then
  505.     ReadOut = "."
  506.     DecimalFlag = False
  507.     End If
  508.     If DecimalFlag Then
  509.     ReadOut = ReadOut + Number(Index).Caption
  510.     Else
  511.     ReadOut = Left(ReadOut, InStr(ReadOut, ".") - 1) + Number(Index).Caption + "."
  512.     End If
  513.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  514.     LastInput = "NUMS"
  515. End Sub
  516. ' Click event procedure for operator keys (+, -, x, /, =).
  517. ' If the immediately preceeding keypress was part of a
  518. ' number, increment NumOps. If one operand is present,
  519. ' set Op1. If two are present, set Op1 equal to the
  520. ' result of the operation on Op1 and the current
  521. ' input string, and display the result.
  522. Sub Operator_Click (Index As Integer)
  523.     TempReadout = ReadOut
  524.     If LastInput = "NUMS" Then
  525.     NumOps = NumOps + 1
  526.     End If
  527.     Select Case NumOps
  528.     Case 0
  529.     If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  530.         ReadOut = "-" & ReadOut
  531.         LastInput = "NEG"
  532.     End If
  533.     Case 1
  534.     Op1 = ReadOut
  535.     If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  536.         ReadOut = "-"
  537.         LastInput = "NEG"
  538.     End If
  539.     Case 2
  540.     Op2 = TempReadout
  541.     Select Case OpFlag
  542.         Case "+"
  543.         Op1 = Val(Op1) + Val(Op2)
  544.         Case "-"
  545.         Op1 = Op1 - Op2
  546.         Case "X"
  547.         Op1 = Op1 * Op2
  548.         Case "/"
  549.         If Op2 = 0 Then
  550.            MsgBox "Can't divide by zero", 48, "Calculator"
  551.         Else
  552.            Op1 = Op1 / Op2
  553.         End If
  554.         Case "="
  555.         Op1 = Op2
  556.         Case "%"
  557.         Op1 = Op1 * Op2
  558.         End Select
  559.     ReadOut = Op1
  560.     NumOps = 1
  561.     End Select
  562.     If LastInput <> "NEG" Then
  563.     LastInput = "OPS"
  564.     OpFlag = Operator(Index).Caption
  565.     End If
  566. End Sub
  567. Sub Panel3D7_MouseDown (Button As Integer, Shift As Integer, x As Single, Y As Single)
  568. MouseDownFlag = True
  569. panel3d7.Font3D = 4
  570. End Sub
  571. Sub Panel3D7_MouseMove (Button As Integer, Shift As Integer, x As Single, Y As Single)
  572. If MouseDownFlag = True Then
  573.   If Counter > 10 Then
  574.     panel3d7.Left = x '+ (Command3d1.Width/4)
  575.     Counter = 0
  576.     If x > 400 Then
  577.       End
  578.     End If
  579.   Else
  580.     Counter = Counter + 1
  581.   End If
  582. End If
  583. End Sub
  584. Sub Panel3D7_MouseUp (Button As Integer, Shift As Integer, x As Single, Y As Single)
  585. MouseDownFlag = False
  586. panel3d7.Font3D = 1
  587. End Sub
  588. ' Click event procedure for percent key (%).
  589. ' Compute and display a percentage of the first operand.
  590. Sub Percent_Click ()
  591.     ReadOut = ReadOut / 100
  592.     LastInput = "Ops"
  593.     OpFlag = "%"
  594.     NumOps = NumOps + 1
  595.     DecimalFlag = True
  596. End Sub
  597.